<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/commons/cssinclude.jsp"></jsp:include>
<jsp:include page="/jsp/commons/scriptinclude.jsp"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>晶品科技信息管理系统-项目中心</title>

</head>
<body>
	<%--<jsp:include page="/jsp/commons/top.jsp"></jsp:include> --%>
	<div class="mainbox">

		<form method="post" action="${ctx}/dispatch/dispatchAction!add.do"
			id="frmDispatchAdd">
			<input type="hidden" id="hbActionType" value="${actionType}" />
			<div class="main_content">
				<%--<%@include file="/jsp/commons/leftMenu.jsp"%> --%>
				<div class="main_right">
					<!--面包屑 begin-->
					<div class="main_rightbox">
						<div class="ec_crumb_kc">
							<span><a class="icon_up" href="#">上一页</a><a
								class="icon_index" href="#">首页</a></span>当前位置：首页&nbsp;&gt;&nbsp;项目中心&nbsp;&gt;&nbsp;售后部&nbsp;&gt;&nbsp;
								<em>
								<c:choose>
								<c:when test="${actionType eq '0'}">报修</c:when>
								<c:when test="${actionType eq '1'}">修改</c:when>
								<c:when test="${actionType eq '2'}">详情</c:when>
								<c:when test="${actionType eq '3'}">回访</c:when>
								</c:choose>
								
								</em>
						</div>
					</div>
					<!--基本信息 begin-->
					<div class="ty_border">
						<div class="ty_head">
							<span class="icon4"></span>甲方资料
						</div>
						<div class="sx_body">
							<dl class="clearfix">
								<dt style="display: none;">甲方资料</dt>

								<dd>
									<label class="name">报修日期：</label><span class="toname"> <input
										type="text" value="" class="Wdate" onClick="WdatePicker()"
										id="repairDate" name="dispatch.repairDate" title="报修日期"
										 
										class="winput3" />
									</span>
									<div class="fl">
										<em id="repairDateTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">客户名称：</label><span class="toname"> 
									<input
										type="hidden" value="" id="customerId"
										name="dispatch.customerId"  />
								     <input
										type="text" value="" id="customerName"
										name="dispatch.customerName" title="客户名称"
										 
										class="winput3" />
									</span>
									<button class="searchBtn dingwei" type="button" id="btnCustomerName"></button>
									<div class="fl">
										<em id="customerNameTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">报修联系人：</label> <span class="toname">
										<input type="text" id="repairpeopleName" value=""
										name="dispatch.repairpeopleName" title="报修联系人"
										 
										class="winput3" />
									</span>
									<div class="fl">
										<em id="repairpeopleNameTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">报修联系电话：</label><span class="toname"><input
										type="text" id="repairPeoplePhone" value=""
										name="dispatch.repairPeoplePhone" title="报修联系电话"
										 
										class="winput3" /></span>
									<div class="fl">
										<em id="repairPeoplePhoneTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">工程质量保修期限：</label><span class="toname">

										<textarea rows="30" cols="100" id="warrantyPeriod"
											name="dispatch.warrantyPeriod" title="工程质量保修期限"
											 
											class="winput3"></textarea>
									</span>
									<div class="fl">
										<em id="warrantyPeriodTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">保修情况记录：</label><span class="toname">

										<textarea rows="30" cols="100" id="warranty"
											name="dispatch.warranty" title="保修情况记录"
											 
											class="winput3"></textarea>
									</span>

									<div class="fl">
										<em id="warrantyTip"></em>
									</div>
								</dd>

							</dl>
						</div>
					</div>
					<!--乙方资料 begin-->
					<div class="ty_border">
						<div class="ty_head">
							<span class="icon4"></span>乙方信息
						</div>
						<div class="sx_body">
							<dl class="clearfix">
								<dt style="display: none;">乙方资料</dt>

								<dd>
									<label class="name">路线：</label><span class="toname"> 
									
									 <select id="pathId"
										name="dispatch.pathId"
										style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										 
										<option value="">---请选择---</option>
										<c:forEach items="${lstPath }" var="path" >
										<option value="${path.value }"  <c:if test="${customer.pathId eq path.value}">selected="selected"</c:if>>${path.name}</option>
										</c:forEach>
									</select>
									</span>
									<div class="fl">
										<em id="pathIdTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">接单员：</label><span class="toname"> 
									<select id="orderPeople" name="dispatch.orderPeople" style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										<option value="">---请选择---</option>
										<c:forEach items="${lstUsers }" var="orderUser">
									    <option value="${orderUser.userCode }" 
									    <c:if test="${orderUser.userCode eq  dispatch.orderPeople}">
									    selected="selected" 
									    </c:if>>${orderUser.name}</option>
										</c:forEach> 
									</select>
									</span>
									 
									<div class="fl">
										<em id="orderPeopleTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">维修技术员：</label> <span class="toname">
										
										 
									    <input type="hidden" id="maintenanceManId" value="" name="dispatch.maintenanceManId"  />
										
									    <input type="text" id="maintenanceManName" value="" title="维修技术员"
										  class="winput3" />
										 
									</span>
									<button class="searchBtn dingwei" type="button" id="btnMaintenanceManId"></button>
									<div class="fl">
										<em id="maintenanceManIdTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">技术员电话：</label><span class="toname"><input
										type="text" id="maintenanceManPhone" value=""
										name="dispatch.maintenanceManPhone" title="商品短标题"
										 
										class="winput3" /></span>
									<div class="fl">
										<em id="maintenanceManPhoneTip"></em>
									</div>
								</dd>

							</dl>
						</div>
					</div>

					<!--项目资料 begin-->
					<div class="ty_border">
						<div class="ty_head">
							<span class="icon4"></span>项目资料
						</div>
						<div class="sx_body">
							<dl class="clearfix">
								<dt style="display: none;">项目资料</dt>

								<dd>
									<label class="name">项目名称：</label><span class="toname"> <input
										type="text" value="" id="name" name="dispatch.name"
										title="项目名称" 
										 class="winput3" />
									</span>
									<div class="fl">
										<em id="nameTip"></em>
									</div>
								</dd>
								
								<dd>
									<label class="name">保修类型：</label>
									 <span class="toname"> 
									   <!-- lstDispatchTypes -->
									   
									  <select id="dispatchType"
										name="dispatch.dispatchType"
										style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										<option value="">---请选择---</option>
										<c:forEach items="${lstDispatchTypes}" var="path" >
										<option value="${path.value }"  <c:if test="${dispatch.dispatchType eq path.value}">selected="selected"</c:if>>${path.name}</option>
										</c:forEach>
									 </select>
									   
									</span>
									<div class="fl">
										<em id="dispatchTypeTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">是否出库：</label><span class="toname">  
										<select id="outBound" name="dispatch.outBound" style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										<option value="">---请选择---</option>
										<option value="0">  不出库        </option>
										<option value="1">  出     库        </option>
									</select>
									</span>
									<div class="fl">
										<em id="outBoundTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">维修单号：</label> <span class="toname">
										<input type="text" id="projectCode" value=""
										name="dispatch.projectCode" title="维修单号"
										 
										class="winput3" />
									</span>
									<div class="fl">
										<em id="projectCodeTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">故障原因：</label><span class="toname">
										<textarea rows="30" cols="100" id="cause"
											name="dispatch.cause" title="故障原因"
											 
											class="winput3"></textarea>
									</span>
									<div class="fl">
										<em id="causeTip"></em>
									</div>
								</dd>
								<dd>
									<label class="name">维修情况说明：</label><span class="toname">
										<textarea rows="30" cols="100" id="maintenanceInfo"
											name="dispatch.maintenanceInfo" title="维修情况说明"
											 
											class="winput3"></textarea>
									</span>
									<div class="fl">
										<em id="maintenanceInfoTip"></em>
									</div>
								</dd>

							</dl>
						</div>
					</div>
                   <c:if test="${actionType eq '3'}">
                    <!--回访信息 begin-->
					<div class="ty_border">
						<div class="ty_head">
							<span class="icon4"></span>回访信息
						</div>
						<div class="sx_body">
							<dl class="clearfix">
								<dt style="display: none;">回访信息</dt>

								<dd>
									<label class="name">回访跟单员：</label><span class="toname"> 
                                    <select id="visitMan" name="dispatch.visitMan" style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										<option value="">---请选择---</option>
										<c:forEach items="${lstUsers }" var="orderUser">
									    <option value="${orderUser.userCode }" 
									    <c:if test="${orderUser.userCode eq  dispatch.orderPeople}">
									    selected="selected" 
									    </c:if>>${orderUser.name}</option>
										</c:forEach> 
									</select>
									</span>
									<div class="fl">
										<em id="visitManTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">回访满意度：</label><span class="toname">  
										 <input type="radio" value="15" style="width:18px;" name="dispatch.visitSatisfaction">好
										 <input type="radio" value="10" style="width:18px;" name="dispatch.visitSatisfaction">中
										 <input type="radio" value="5" style="width:18px;" name="dispatch.visitSatisfaction">差
									</span>
									<div class="fl">
										<em id="visitSatisfactionTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">回访分值：</label> <span class="toname">
										<input type="text" id="visitScore" value=""
										name="dispatch.visitScore" title="回访分值"
										 
										class="winput3" />
									</span>
									<div class="fl">
										<em id="visitScoreTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">回访日期：</label><span class="toname">
										<input type="text" id="visitDate"
											name="dispatch.visitDate" title="回访日期"  class="Wdate" onClick="WdatePicker()"
											 
											class="winput3"> 
									</span>
									<div class="fl">
										<em id="maintenanceInfoTip"></em>
									</div>
								</dd>
								
								<dd>
									<label class="name">回访结果：</label><span class="toname">
										<textarea rows="30" cols="100" id="visitResult"
											name="dispatch.visitResult" title="回访结果"
											 
											class="winput3"></textarea>
									</span>
									<div class="fl">
										<em id="visitResultTip"></em>
									</div>
								</dd>

							</dl>
						</div>
					</div>
                    </c:if>
                    
					<!--保存取消 begin-->
					<div class="baocun">
						<button id='btnQuit' type="button" class="gybg qxBtn">取消</button>
						<input type="button" id="btnSave" class="gybg saveBtn"
							value="保存" />
					</div>
				</div>
			</div>
		</form>

	</div>

	<!--客户弹出层 begin-->
	<div id="customerDialog" style="display: none">
	</div>
	
	<!--维修技术员弹出层 begin-->
	<div id="userDialog" style="display: none">
	</div>

	<!-- JQ -->

	<script type="text/javascript">
	
	    //页面初始化
		$(function(){
			var myDate = new Date();
			       //获取当前年份(2位)
			var y=myDate.getFullYear();    //获取完整的年份(4位,1970-????)
			var m=(myDate.getMonth()+1)<10?"0"+(myDate.getMonth()+1):(myDate.getMonth()+1);       //获取当前月份(0-11,0代表1月)
			var d=myDate.getDate()<10?"0"+myDate.getDate().toString():myDate.getDate();        //获取当前日(1-31)
			var h=myDate.getHours()<10?"0"+myDate.getHours().toString():myDate.getHours();       //获取当前小时数(0-23)
			var m=myDate.getMinutes()<10?"0"+myDate.getMinutes().toString():myDate.getMinutes();     //获取当前分钟数(0-59)
			var s=myDate.getSeconds()<10?"0"+myDate.getSeconds().toString():myDate.getSeconds();     //获取当前秒数(0-59)
			var ml=myDate.getMilliseconds()<10?"0"+myDate.getMilliseconds().toString():myDate.getMilliseconds();      //获取当前毫秒数(0-999)
			$("#projectCode").val(y.toString()+m.toString()+d.toString()+h.toString()+m.toString()+s.toString()+ml.toString());
		});
	
	    //异步加载维修人员
	    $("#btnMaintenanceManId").click( function(){
	    	 
	    	 $.post(
		     		 "${ctx}/user/userAction!initDialog.action", 
		 				{random:Math.random()}, 
		 				function(data){
		 					$("#userDialog").html(data);
							//加载弹出层
		 					art.dialog({
		 					    id: 'msg',
		 					    title: '选择属性',
		 					    content: $("#userDialog").html(),//绑定内容
		 					    ok: function () {
		 					    
		 					    	var manIds=[];
		 					    	var manNames=[];
		 					    	var manMobiles=[];
		 					    	  $('input[name="userSelected"]:checked').each(function(){    
		 					    		  manIds.push( $(this).attr("user_code"));
		 					    		  manNames.push( $(this).attr("user_name"));
		 					    		  manMobiles.push( $(this).attr("user_mobile"));
		 					    		  });    
		 					    	 $("#maintenanceManId").val(manIds.join(","));
		 					    	 $("#maintenanceManName").val(manNames.join(","));
		 					    	 $("#maintenanceManPhone").val(manMobiles.length>0?manMobiles[0]:"");
		 					    },//确定时回调函数
		 					    cancel:true//取消时回调函数
		 					    
		 					});
		 				}
		      
		        );
	    } );
		//异步加载客户名称
		$("#btnCustomerName").click(function() {
			 $.post(
		     		 "${ctx}/customer/customerAction!initCustomersDialog.action", 
		 				{random:Math.random()}, 
		 				function(data){
		 					$("#customerDialog").html(data);
							//加载弹出层
		 					art.dialog({
		 					    id: 'msg',
		 					    title: '选择属性',
		 					    content: $("#customerDialog").html(),//绑定内容
		 					    ok: function () {
		 					    	var selectCustomerObj= $("input[name='customerSelected']:checked");
		 					    	 $("#customerName").val($(selectCustomerObj).attr("customerName"));
		 					    	 $("#customerId").val($(selectCustomerObj).attr("customerId"));
		 					    	 $("#repairpeopleName").val()==""? $("#repairpeopleName").val($(selectCustomerObj).attr("linkman")):$("#repairpeopleName").val();
		 					    	 $("#repairPeoplePhone").val()==""? $("#repairPeoplePhone").val($(selectCustomerObj).attr("contactphone")): $("#repairPeoplePhone").val();
		 					    },//确定时回调函数
		 					    cancel:true//取消时回调函数
		 					    
		 					});
		 				}
		      
		        );
			
			 
		});
		
		function showMsg(dom,msgFlag,str){
			$("#"+dom+"Tip").html(setPrompt(msgFlag,str,"${ctx}"));
			$("#"+dom).focus();
		}
		
		

		//根据状态为来决定是增加还是修改
		$("#btnSave")
				.click(
						function() {
							var strActionType = $("#hbActionType").val();
							if (strActionType != "") {
								if (strActionType == 0) {
									//新增操作
									//验证编码
									if(frmValidator()){
										 
										$("#frmDispatchAdd") .attr("action", "${ctx}/dispatch/dispatchAction!add.action");
										$("#frmDispatchAdd").submit();
									}
									 
								} else if (strActionType == 1) {
									//修改操作
									$("#frmDispatchAdd")
											.attr("action",
													"${ctx}/dispatch/dispatchAction!updateDispatch.action");
									$("#frmDispatchAdd").submit();
								} else {
									alert("系统错误，请联系系统管理员！");
								}
							} else {
								alert("系统错误，请联系系统管理员！");
							}
						});
		
		
		//验证表单
		function frmValidator(){
			var flag=true;
			if($("#repairDate").val()==""){
				flag=false;
				showMsg("repairDate","onError","报修时间不能为空");
			}else{
				$("#repairDateTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			if($("#customerName").val()==""){
				flag=false;
				showMsg("customerName","onError","客户名称不能为空");
			}else{
				$("#customerNameTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			if($("#repairpeopleName").val()==""){
				flag=false;
				showMsg("repairpeopleName","onError","报修联系人不能为空");
			}else{
				$("#repairpeopleNameTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			if($("#repairPeoplePhone").val()==""){
				flag=false;
				showMsg("repairPeoplePhone","onError","报修联系电话");
			}else{
				$("#repairPeoplePhoneTip").html(setPrompt("onSuccess","输入正确","${ctx}"));
			}
			return flag; 
		}

		/**
		 * 验证编码
		 * @param code 编码
		 * @param flag 是否异步
		 */
		function codeValidator(code, flag) {
			var result = false;
			//异步验证
			if (flag == "Y") {
				$.post("${ctx}/syspara/sysparaAction!codeValidator.action", {
					random : Math.random(),
					"syspara.code" : code
				}, function(data) {
					var jsonData = strToJson(data);
					if (jsonData.flag == "success") {
						$("#sysparaCodeTip")
								.html(
										setPrompt("onSuccess", jsonData.data,
												"${ctx}"));
						result = true;
					} else {
						$("#sysparaCodeTip").html(
								setPrompt("onError", jsonData.errorMsg,
										"${ctx}"));
					}
				});
			} else {
				//同步验证
				var url = "${ctx}/syspara/sysparaAction!codeValidator.action";
				var params = {
					"random" : Math.random(),
					"syspara.code" : code
				};
				$.ajax({
					url : url,
					type : 'post',
					data : params,
					async : false,
					dataType : 'json',
					success : function(data) {
						var jsonData = strToJson(data);
						if (jsonData.flag == "success") {
							$("#sysparaCodeTip").html(
									setPrompt("onSuccess", jsonData.data,
											"${ctx}"));
							result = true;
						} else {
							$("#sysparaCodeTip").html(
									setPrompt("onError", jsonData.errorMsg,
											"${ctx}"));
						}
					},
					error : function() {
						alert("系统错误");
						queryCategory();
					}
				});
			}
			return result;
		}

		/**
		 *绑定值改变事件
		 */
		$("#sysparaCode").change(
				function() {
					$("#sysparaCodeTip").html(
							setPrompt("onLoad", "正在验证数据，请稍等", "${ctx}"));
					codeValidator($("#sysparaCode").val(), "Y");
				});

		$(".ctnGdpOptionPanel li").hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});
		$(".arrowname").click(function() {
			var domUl = $(this).parent().find(".ctnGdpOptionPanelMask");
			var domArrow = $(this).find("span.arrowdown");
			if (domArrow.hasClass("arrowUp")) {
				domArrow.removeClass("arrowUp");
				domUl.show();
			} else {
				domArrow.addClass("arrowUp");
				domUl.hide();
			}
		});
		
		//取消事件
		$("#btnQuit").click(function(){
			art.dialog.confirm('你确认放弃页面操作，返回列表？', function(){
				location.href ="${ctx}/dispatch/dispatchAction!listInit.action";
			}, function(){
			     
			});
		});
	</script>
</body>
</html>